package com.test.liuhb.test.Util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.test.liuhb.test.R;

import java.util.List;

/**
 * Created by xu.ch on 2016/5/18.
 */
public class BlueToothDevicesAdapter extends BaseAdapter {
    List<BlueToothDevice> mList;
    LayoutInflater mInflater;

    public BlueToothDevicesAdapter(Context context, List<BlueToothDevice> mList) {
        this.mList = mList;
        mInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public BlueToothDevice getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BlueToothDevice item = mList.get(position);
        Holder4TextView holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.m8_i_bluetooth_info, null);
            holder = new Holder4TextView();
            holder.v1 = (TextView) convertView.findViewById(R.id.m8_i_bluetooth_info1);
            holder.v2 = (TextView) convertView.findViewById(R.id.m8_i_bluetooth_info2);
            holder.v3 = (TextView) convertView.findViewById(R.id.m8_i_bluetooth_info3);
            convertView.setTag(holder);
        } else {
            holder = (Holder4TextView) convertView.getTag();
        }
        holder.v1.setText(item.name);
        holder.v2.setText(item.address);
        holder.v3.setText(item.type + "");
        return convertView;
    }
}
